<?php 
header("Content-type:text/html; charset=utf-8");
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(1);
date_default_timezone_set('PRC');

session_start();
require_once 'site_config.php';
require_once 'class/ig2sql.class.php';
$db=new ig2sql();
 
$db->ig2_conn(Mysql_server,Mysql_user,Mysql_pass,Mysql_db,'utf8');

function tellgoto($tell,$goto){
	if($tell){
		echo "<script language=javascript>alert('".$tell."');</script>";
		echo "<script language=javascript>document.location.href='".$goto."';</script>";
	}else{
		echo "<script language=javascript>document.location.href='".$goto."';</script>";
	}
}

function getToken($url){
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
	$row=curl_exec($ch); 
	return $row;
}

function ticket_req($access_token,$json){
	$ch = curl_init();//初始化curl
	curl_setopt($ch, CURLOPT_URL, 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$access_token);//设置链接
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置是否返回信息
	curl_setopt($ch, CURLOPT_HTTPHEADER, 'Content-type: text/json');//设置HTTP头
	curl_setopt($ch, CURLOPT_POST, 1);//设置为POST方式
	curl_setopt($ch, CURLOPT_POSTFIELDS, $json);//POST数据
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	$response = curl_exec($ch);//接收返回信息
	if(curl_errno($ch)){
		//出错则显示错误信息
		echo curl_error($ch);
	}
	curl_close($ch);//关闭curl链接
	return $response;//返回信息
}

function getIp(){
	if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')){
		$ip = getenv('HTTP_CLIENT_IP');
	}elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')){
		$ip = getenv('HTTP_X_FORWARDED_FOR');
	}elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')){
		$ip = getenv('REMOTE_ADDR');
	}elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')){
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	return preg_match("/[\d\.]{7,15}/", $ip, $matches) ? $matches[0] : 'unknown';
}
?>
